<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>匹配</title>
		<style>
			*{box-sizing: border-box;}
			div.container div{
				display: inline-block;
				width:300px;
				margin:20px;
				border:2px solid #269ABC;
				height:200px;
				float:left ;
			}
			div.container div span{
				display: inline-block;
				padding:20px;
			}
		</style>
	</head>
	<body>
		<textarea name="" rows="" cols=""></textarea>
		<p><button>匹配房间</button></p>
		<div class="container">
		</div>
		<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
		<script>
//			var rommList = {
//				romm1:["小里1","小里2","小里3"],
//				romm2:["小白1","小白2","小白3","小白4"],
//				romm3:["小里1","小里2"],
//				romm4:["小里1","小里2","小里3","小里3","小里3"],
//				romm5:["小里1",],
//				romm6:["小里1","小里2","小里3"],
//			}
			var rommList = [	
						{name:["小里1","小里2","小里3"]},
						{name:["小白1","小白2","小白3","小白4"]},
						{name:["小里1","小里2"]},
						{name:["小里1","小里2","小里3","小里3","小里3"]},
						{name:["小里1"]},
						{name:["小里1","小里2","小里3"]}
					]


			$.each(rommList,function(index,item){
//				$("div.container").append("<div></div>");
				var str = "<div>"
				$.each(item.name,function(index1,item1){
					str += "<span>"+item1+"</span>";
				})
				str += "</div>";
				$("div.container").append(str);
			})
			$("button").click(function(){
			for(var i = 0;i<1;i++){
					var n = rommList.length;
					n = n-1;
					var index = Math.round(Math.random()*n);
					if(rommList[index].name.length < 6){
						rommList[index].name.push("葛琼1");
						console.log(rommList)
						newDiv()
					}else{
						i--;
					}
				}
			})
			
			function newDiv(){
				$("div.container div").remove();
							$.each(rommList,function(index,item){
//				$("div.container").append("<div></div>");
				var str = "<div>"
				$.each(item.name,function(index1,item1){
					str += "<span>"+item1+"</span>";
				})
				str += "</div>";
				$("div.container").append(str);
			})
			}
		</script>
	</body>
</html>
